/*
 * @Author: 庄东东
 * @Date: 2021-09-01 09:35:14
 * @LastEditTime: 2021-09-01 18:20:23
 * @LastEditors: 庄东东
 * @Description:
 * @FilePath: \romance\src\store\userInfo.ts
 */
import { Module } from "vuex";
import { GlobalDataProps } from "./index";
import { assign } from "lodash-es";
import { Sex, Whether } from "../config/enum";
export interface UserProps {
  info: Info;
  preference: Preference;
}
export interface Preference {
  city: number;
  sex: number;
  priority: boolean;
  minAge: number;
  maxAge: number;
}
export interface Info {
  vx: string;
  mobile: number;
  sex: number;
  name: string;
  avatar: string;
  age: number;
  province: string;
  city: string;
  school: string;
  graduation: number;
  she: string;
  myself: string;
  provinceCode: number;
  cityCode: number;
}
const userInfo: Module<UserProps, GlobalDataProps> = {
  state: {
    info: {
      vx: "123",
      mobile: 15060950558,
      sex: 0,
      name: "你好",
      avatar: "https://img01.yzcdn.cn/vant/cat.jpeg",
      age: 18,
      province: "福建省",
      provinceCode: 110101,
      city: "泉州市",
      cityCode: 110101,
      school: "武夷学院",
      graduation: 0,
      she: "11",
      myself: "222"
    },
    preference: {
      city: 0,
      sex: 0,
      priority: true,
      minAge: 18,
      maxAge: 40
    }
  },
  getters: {
    getPreferenceAge: (state) => {
      return state.preference.minAge + " - " + state.preference.maxAge;
    },
    getInfoAddress: (state) => {
      return state.info.province + " - " + state.info.city;
    },
    getInfoGraduation: (state) => {
      return Whether[state.info.graduation];
    },
    getInfoSex: (state) => {
      return Sex[state.info.sex];
    }
  },
  mutations: {
    setPreference(state, param: Partial<Info>) {
      assign(state.preference, param);
    },
    setInfo(state, param: Partial<Info>) {
      assign(state.info, param);
    }
  }
};

export default userInfo;
